package com.example.kx026;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

/**
 * 复选框 案例
 */
public class MainActivity extends AppCompatActivity {

    Button btn_login, btn_concel;
    CheckBox cb1, cb2, cb3;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        btn_login = findViewById(R.id.btn_login);
        btn_concel = findViewById(R.id.btn_cancel);
        cb1 = findViewById(R.id.checkbox1);
        cb2 = findViewById(R.id.checkbox2);
        cb3 = findViewById(R.id.checkbox3);


        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String checked="";
                if(cb1.isChecked()){
                    checked+=cb1.getText();
                }
                if(cb2.isChecked()){
                    checked+=cb2.getText();
                }
                if(cb3.isChecked()){
                    checked+=cb3.getText();
                }

                Toast.makeText(MainActivity.this, checked, Toast.LENGTH_SHORT).show();


            }
        });


    }
}